package ase.eleitweg.server;

import java.rmi.server.ExportException;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.*;

import com.google.inject.Inject;

import ase.eleitweg.common.*;
import ase.eleitweg.server.db.WorkflowDAO;

public class ServerAdminController extends AbstractServerController implements
		ServerAdminHandle {
	
	@Inject RunManager rm;
	@Inject UserManager um;
	@Inject WorkflowManager wm;
	@Inject AdminLoginInterface ali;
	public ServerAdminController() {
		super();
	}
	
	public void registerClient(ClientHandle ch) throws RemoteException {
		ali.addClientHandle(ch);
	}

	public RunManager getRunManager() throws RemoteException {
		// return RunController.getRemoteInstance();
		try {
			return (RunManager) UnicastRemoteObject.exportObject(rm, 0);
		} catch (ExportException e) {
			// the object already exported
			return rm;
		}
	}

	public WorkflowManager getWFManager() throws RemoteException {
		// return WorkflowController.getRemoteInstance();
		try {
			return (WorkflowManager) UnicastRemoteObject.exportObject(wm, 0);
		} catch (ExportException e) {
			// the object already exported
			return wm;

		}
	}

	public UserManager getUserManager() throws RemoteException {
		// return UserController.getRemoteInstance();
		try {
			return (UserManager) UnicastRemoteObject.exportObject(um, 0);
		} catch (ExportException e) {
			// the object already exported
			return um;
		}
	}

}
